import { onMounted, onBeforeUnmount } from 'vue'
import PhotoSwipeLightbox from 'photoswipe/lightbox'

// 图片预览
export function usePhotoSwipe() {
    let lightbox = null

    onMounted(() => {
        lightbox = new PhotoSwipeLightbox({
            gallery: 'body',
            children: '.pswp-img',
            pswpModule: () => import('photoswipe')
        })
        lightbox.init()
    })

    onBeforeUnmount(() => {
        if (lightbox) {
            lightbox.destroy()
            lightbox = null
        }
    })
}
